import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:二维数组、类和对象的讲解
 * User: 阿宾
 * Date: 2024-05-07
 * Time: 13:55
 */
//狗
class Dog{
    //狗的属性
    public String name;
    public int age;
    public String color;
    //狗的行为
    public void barks(){
        System.out.println(name+"汪汪叫");
    }
}
public class Test01 {
    public static void main(String[] args) {
        //通过new关键字实例化一个Dog对象
        Dog dog = new Dog();
        //dog就是一个引用，指向了Dog对象
        //通过.访问对象的属性
        /*dog.name = "阿黄";
        dog.age = 6;
        dog.color = "黄色";
        System.out.println(dog.name);
        System.out.println(dog.age);
        System.out.println(dog.color);
        dog.barks();*/

        Student stu = new Student();
        System.out.println(stu);
    }
    public static void main3(String[] args) {
        /*int[][] arr = new int[][]{{1,2,3},{4,6,8}};
        System.out.println(Arrays.deepToString(arr));*/

        //不规则的二维数组
        int[][] arr1 = new int[2][];//可以不指定列数，而C语言中需要指定列数
        /*arr1[0] = new int[]{1,2,3};
        arr1[1] = new int[]{2,4,6,8,10};*/
        for (int i = 0; i < arr1.length; i++) {
            for (int j = 0; j < arr1[i].length; j++) {
                System.out.print(arr1[i][j] + " ");
            }
            System.out.println();
        }
        System.out.println(Arrays.deepToString(arr1));
    }
    public static void main2(String[] args) {
        //二维数组的创建
        int[][] arr1 = {{1,2,3},{4,5,6}};
        int[][] arr2 = new int[][]{{1,2,3},{4,5,6}};
        int[][] arr3 = new int[2][3];//没有标明初始值，则初始化都为0

        //二维数组的遍历
        for (int i = 0; i < 2; i++) {
            for (int j = 0; j < 3; j++) {
                System.out.print(arr1[i][j] + " ");
            }
            System.out.println();
        }
        //如何确定行和列？
        //二维数组其实就是一维数组，只不过存储的元素是地址，对应的是另一个一维数组
        for (int i = 0; i < arr1.length; i++) {
            //arr1.length计算的是数组的元素个数，{{1,2,3},{4,5,6}}，也就是有两个元素{1,2,3}，{4,5,6}
            for (int j = 0; j < arr1[i].length; j++) {
                //arr1[0].length 表示的是元素{1,2,3}的长度，也就是第一行的长度...
                System.out.print(arr1[i][j] + " ");
            }
            System.out.println();
        }
    }
    public static void main1(String[] args) {
        int[] arr = {1, 2, 3, 4};
        reverse(arr);
        System.out.println(Arrays.toString(arr));
    }
    public static void reverse(int[] arr) {
        int left = 0;
        int right = arr.length - 1;
        while (left < right) {
            int tmp = arr[left];
            arr[left] = arr[right];
            arr[right] = tmp;
            left++;
            right--;
        }
    }
}
